package com.abe.bathsystem.contract.presenter;

import com.abe.bathsystem.contract.CommonContract;
import com.abe.bathsystem.contract.CommonModel;
import com.abe.bathsystem.entity.ReqBaseNoDataEntity;
import com.abe.bathsystem.entity.ReqConstant;
import com.abe.bathsystem.entity.http.HttpBathPosStateEntity;
import com.abe.bathsystem.entity.http.HttpUserEntity;
import com.abe.libcore.utils.normal.ToastUtils;
import com.abe.mvpcore.BasePresenter;
import com.abe.mvpcore.OnResultListener;


public class OrderPresenter extends BasePresenter<CommonContract.OrderView, CommonModel> implements CommonContract.OrderPresenter {
    @Override
    public void orderStart(final HttpUserEntity userEntity, final HttpBathPosStateEntity posStateEntity, final boolean isDeviceSend) {
        getModel().orderStart(userEntity, posStateEntity, new OnResultListener<ReqBaseNoDataEntity>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onEnd() {
                OrderPresenter.this.onEnd(OrderPresenter.class.getSimpleName() + "-orderStart");
            }

            @Override
            public void onSuccess(ReqBaseNoDataEntity data) {
                if (OrderPresenter.this.onSuccess(data)) {
                    boolean isSuccess = data.getCode() == ReqConstant.NET_RESULT_OK;
                    getView().onOrderStart(userEntity, posStateEntity, isSuccess, data.getMsg(), isDeviceSend);
                }
            }

            @Override
            public void onFailure(String message) {
                OrderPresenter.this.onFailure(OrderPresenter.class.getSimpleName() + "-orderStart");
            }
        });
    }

    @Override
    public void orderEnd(final boolean isDeviceSend, final HttpUserEntity userEntity, final HttpBathPosStateEntity posStateEntity, float xi_yu_da, float xi_yu_xiao, float fee_total,
                         float fee_xi_yu_da, float fee_xi_yu_xiao, float fee_chui_feng, float fee_chong_dian) {
        getModel().orderEnd(userEntity, posStateEntity, xi_yu_da, xi_yu_xiao, fee_total, fee_xi_yu_da, fee_xi_yu_xiao,
                fee_chui_feng, fee_chong_dian, new OnResultListener<ReqBaseNoDataEntity>() {
                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onEnd() {
                        OrderPresenter.this.onEnd(OrderPresenter.class.getSimpleName() + "-orderEnd");
                    }

                    @Override
                    public void onSuccess(ReqBaseNoDataEntity data) {
                        if (OrderPresenter.this.onSuccess(data)) {
                            getView().onOrderEnd(userEntity, posStateEntity, data.getCode() == ReqConstant.NET_RESULT_OK, isDeviceSend);
                        }
                    }

                    @Override
                    public void onFailure(String message) {
                        OrderPresenter.this.onFailure(OrderPresenter.class.getSimpleName() + "-orderEnd");
                    }
                });
    }
}
